package com.mstar.qs.common;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.apache.log4j.PropertyConfigurator;

public class GlobalConstants {

	public static final String LINE_SEPARATOR = System
			.getProperty("line.separator");
	public static final String OS = System.getProperty("os.name");


	public static List<String> splitStringByComma(String s){
		String[] ss=s.split(",");
		return Arrays.asList(ss);
	}

	public static String buildTreeComponent(Entry root) throws DefQsException{
		return buildTreeComponent(root, 0, root.attribute("placeholder"));
	}

	public static String buildTreeComponent(Entry root, int level, String ph) throws DefQsException {

		StringBuilder sb = new StringBuilder();
		

		sb.append("{");
		sb.append("val:").append("'").append(Placeholder.placeholderReplacement(root.attribute("action"), ph))
				.append("',");
		sb.append("txt:").append("'").append(root.attribute("view-name"))
				.append("',");

		sb.append("className:").append("'").append("level" + level)
				.append("',");

		String ep = root.attribute("auto-expand");
		if (ep != null)
			sb.append("autoExpand:").append(ep);
		else
			sb.append("autoExpand:").append("false");
		sb.append(",");

		sb.append("children:").append("[");
		Collection<Entry> se = root.retrieveSubEntries();
		if (se != null && se.size() > 0) {
			int c = 0;
			for (Entry sei : se) {
				if (c != 0)
					sb.append(",");
				sb.append(buildTreeComponent(sei, level + 1, ph));
				c++;
			}
		}
		sb.append("]");
		sb.append("}");
		return sb.toString();

	}

	public static void initLog4jForTest() {
		PropertyConfigurator
				.configureAndWatch("D:/data/conf/log4j.properties");
	}

}
